<?php
	echo "<h2 id='contentTitle'>".$pageTitle."</h2>";
	echo $this->renderElement('message');

	echo $html->link('Cadastrar post', '/posts/add/');
	echo "<br /><br />";

	if (isset($posts) && is_array($posts) && (!empty($posts))) {
		echo "<table>";
		echo "<tr class='sort'>";
			echo "<th>Id</th>";
			echo "<th>Titulo</th>";
			echo "<th>Texto</th>";
			echo "<th>CriadoEm</th>";
			echo "<th>CriadoPor</th>";
			echo "<th>Usuario</th>";
			echo "<th>Forum</th>";
			echo "<th>Editar</th>";
			echo "<th>Excluir</th>";
		echo "</tr>";

		$i=0;
		foreach ($posts as $post) {
			if (($i++ % 2) == 1) $zebrado = " class='oddTr' ";
			else $zebrado = "";
			echo "<tr ".$zebrado.">";
			echo "<td>".$html->link($post['Post']['id'],'/posts/view/'.$post['Post']['id'])."</td>";
			echo "<td>".$post['Post']['titulo']."</td>";
			echo "<td>".$post['Post']['texto']."</td>";
			echo "<td>".$post['Forum']['criadoEm']."</td>";
			echo "<td>".$post['Forum']['criadoPor']."</td>";
			echo "<td>".$html->link($post['Usuario']['login'],'/usuarios/view/'.$post['Usuario']['id'])."</td>";
			echo "<td>".$html->link($post['Forum']['titulo'],'/forums/view/'.$post['Forum']['id'])."</td>";
			echo "<td>".html_entity_decode($html->link($html->image('fileedit.png',array('class'=>'opIcon')), '/posts/edit/'.$post['Post']['id']))."</td>";
			echo "<td>".html_entity_decode($html->link($html->image('filedel.png',array('class'=>'opIcon')), '/posts/delete/'.$post['Post']['id'], array(), 'Confirma a exclusão deste item?'))."</td>";
			echo "</tr>";
		}
		echo "<tr id='footerTable'><td colspan='100%'></td></tr>";
		echo "</table>";
	}
